package com.turnengine.client.local.location.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Coordinate Serializer.
 */
public class CoordinateSerializer implements ICoordinateSerializer {

	@Override
	public ICoordinate readObject(IDataReader reader) throws IOException {

		// Read fields
		int locationId = reader.readInt();
		int[] coordinates = reader.readIntArray(false);

		// Create object
		ICoordinate object = new Coordinate();
		object.setLocationId(locationId);
		object.setCoordinates(coordinates);
		return object;
	}

	public void writeObject(IDataWriter writer, ICoordinate object) throws IOException {

		// Get fields
		int locationId = object.getLocationId();
		int[] coordinates = object.getCoordinates();

		// Write fields
		writer.writeInt(locationId);
		writer.writeIntArray(coordinates, false);
	}
}
